# alert_manager.py
import time
from collections import defaultdict
from alert import send_alert
from parser import parse_slow_query_log

class AlertManager:
    def __init__(self, cooldown_minutes=10):
        self.last_alert_time = defaultdict(float)
        self.cooldown = cooldown_minutes * 60

    def should_alert(self, fingerprint):
        now = time.time()
        if now - self.last_alert_time[fingerprint] > self.cooldown:
            self.last_alert_time[fingerprint] = now
            return True
        return False

# 使用
alert_manager = AlertManager()
fingerprint = f"long_tx_{int(parse_slow_query_log.tx['duration_sec']/10)}s_rows{parse_slow_query_log.tx['rows_affected']}"
if alert_manager.should_alert(fingerprint):
    send_alert(...)